package svc

import (
	"github.com/elastic/go-elasticsearch/v7"
	"github.com/go-redis/redis/v8"
	"github.com/zeromicro/go-zero/zrpc"
	"gorm.io/gorm"
	"yangming-college/app/speciality/cmd/v1/api/internal/config"
	"yangming-college/app/usercenter/cmd/v1/rpc/usercenter"
	"yangming-college/common/initialize"
)

type ServiceContext struct {
	Config        config.Config
	DB            *gorm.DB
	RedisClient   *redis.Client
	ESClinet      *elasticsearch.Client
	UsercenterRpc usercenter.UserCenter
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config:        c,
		DB:            initialize.DBinit(c.Mysql.Account, c.Mysql.Password, c.Mysql.Host, c.Mysql.Database),
		RedisClient:   initialize.Redisinit(c.Redis.Host, c.Redis.Password),
		ESClinet:      initialize.ESinit(c.ElasticSearchConfig.URL),
		UsercenterRpc: usercenter.NewUserCenter(zrpc.MustNewClient(c.UserRpcConf)),
	}
}
